import md5 from "js-md5";
import { getConfig } from "../config";
/**
 *
 * @returns 当前应用id
 */
export const getAppId = (): string => {
  return getConfig().appId;
};

/**
 *
 * @returns 当前时间戳
 */
export const getTimeStamp = (): number => {
  return new Date().getTime();
};

/**
 *
 * @returns url
 */
export const getPageUrl = () => {
  const {
    location: { href },
  } = window;
  return href;
};

/**
 *  获取用户的 userid
 * @returns 用户id
 */
export const getUserID = () => {
  return getConfig().userId;
};

/**
 *  获取上报数据的基础参数
 * @returns 基础参数
 */
export const getBasicParams = () => {
  const time = getTimeStamp();
  const eventId = md5.hex(getAppId() + getUserID() + time);
  return {
    appId: getAppId(),
    startTime: time,
    pageUrl: getPageUrl(),
    userID: getUserID(),
    eventId: eventId,
  };
};
